/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IngresoComida.java
 *
 * Created on 14-abr-2012, 21:18:19
 */

package gui;

import java.util.ListIterator;
import javax.swing.JOptionPane;
import modelo.Alimento;
import modelo.Cliente;
import modelo.Comida;
import modelo.Restaurante;

/**
 *
 * @author Lenovo
 */
public class IngresoEntrada extends javax.swing.JFrame {

    /** Creates new form IngresoComida */
    private Restaurante restaurante;
    private int mesaPedido;
    private int sillaPedido;
    VentanaPrincipal v;
    public IngresoEntrada(Restaurante restaurante,int mesaPedido, int sillaPedido) {
        initComponents();
        this.restaurante= restaurante;
        this.mesaPedido=mesaPedido;
        this.sillaPedido=sillaPedido;
        this.setLocationRelativeTo(null);
        cargarComboEntradas();
    }
    
    
     /**
     * Carga las comidas de tipo entrada en el combo de entrada
     */
    public void cargarComboEntradas() {
        jCBEntrada.removeAllItems();
        ListIterator<Alimento> iterator = restaurante.getMenu().listIterator();
        while (iterator.hasNext()) {
            Alimento a = iterator.next();
            if (a instanceof Comida) {
                Comida c = (Comida) a;
                if (c.getTipo().equals(Comida.TIPO_ENTRADA)) {
                    jCBEntrada.addItem(c.getNombre());
                }
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPEntrada = new javax.swing.JPanel();
        jLImgEntrada = new javax.swing.JLabel();
        jCBEntrada = new javax.swing.JComboBox();
        jLEntrada = new javax.swing.JLabel();
        jLCantEntrada = new javax.swing.JLabel();
        jSCantEntrada = new javax.swing.JSpinner();
        jBAgregarEntrada = new javax.swing.JButton();
        jBCancelarAgregarEntrada = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Restaurante \"Con Sabor\" - Adicionar Entrada");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPEntrada.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Entrada", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(204, 0, 102))); // NOI18N

        jLImgEntrada.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/entradas.gif"))); // NOI18N
        jLImgEntrada.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jCBEntrada.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jCBEntrada.setForeground(new java.awt.Color(153, 0, 51));
        jCBEntrada.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opción" }));

        jLEntrada.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLEntrada.setForeground(new java.awt.Color(153, 0, 51));
        jLEntrada.setText("Entrada a ordenar:");

        jLCantEntrada.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLCantEntrada.setForeground(new java.awt.Color(153, 0, 51));
        jLCantEntrada.setText("Cantidad para este pedido:");

        javax.swing.GroupLayout jPEntradaLayout = new javax.swing.GroupLayout(jPEntrada);
        jPEntrada.setLayout(jPEntradaLayout);
        jPEntradaLayout.setHorizontalGroup(
            jPEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPEntradaLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLImgEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLCantEntrada)
                    .addComponent(jLEntrada))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCBEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSCantEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPEntradaLayout.setVerticalGroup(
            jPEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPEntradaLayout.createSequentialGroup()
                .addComponent(jLImgEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPEntradaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPEntradaLayout.createSequentialGroup()
                        .addComponent(jCBEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jSCantEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPEntradaLayout.createSequentialGroup()
                        .addComponent(jLEntrada)
                        .addGap(18, 18, 18)
                        .addComponent(jLCantEntrada)))
                .addGap(24, 24, 24))
        );

        jBAgregarEntrada.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAgregarEntrada.setForeground(new java.awt.Color(204, 0, 102));
        jBAgregarEntrada.setText("AGREGAR ENTRADA");
        jBAgregarEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAgregarEntradaActionPerformed(evt);
            }
        });

        jBCancelarAgregarEntrada.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBCancelarAgregarEntrada.setForeground(new java.awt.Color(204, 0, 102));
        jBCancelarAgregarEntrada.setText("CANCELAR");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(230, 230, 230)
                        .addComponent(jBAgregarEntrada)
                        .addGap(53, 53, 53)
                        .addComponent(jBCancelarAgregarEntrada))
                    .addComponent(jPEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCancelarAgregarEntrada)
                    .addComponent(jBAgregarEntrada))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAgregarEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAgregarEntradaActionPerformed
     String alimento= (String)jCBEntrada.getSelectedItem();
     int cantidadEntrada= (Integer) jSCantEntrada.getValue();
     Alimento ali= restaurante.buscarAlimento(alimento);
     if(ali!=null){
         ali.setCantidad(cantidadEntrada);
         Cliente c = restaurante.getClientes()[mesaPedido][sillaPedido];
          String msj =c.modificarPedido(ali, cantidadEntrada);
          JOptionPane.showMessageDialog(null, msj);
         }else{
         JOptionPane.showMessageDialog(null, "Este alimento no esta disponible en el menu");
     }
       
    }//GEN-LAST:event_jBAgregarEntradaActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
       v.cargarConsumoActual();
    }//GEN-LAST:event_formWindowClosed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAgregarEntrada;
    private javax.swing.JButton jBCancelarAgregarEntrada;
    private javax.swing.JComboBox jCBEntrada;
    private javax.swing.JLabel jLCantEntrada;
    private javax.swing.JLabel jLEntrada;
    private javax.swing.JLabel jLImgEntrada;
    private javax.swing.JPanel jPEntrada;
    private javax.swing.JSpinner jSCantEntrada;
    // End of variables declaration//GEN-END:variables

}
